package co.edu.unal.bioingenium.kbmed.knowledge.visualization.vo;

import java.util.HashSet;
import java.util.Set;

/**
 *
 * @author alejandro
 */
public class SubHierarchyNode implements Cloneable {

    private String id;
    private String name;
    private NodeData data;
    private Set<SubHierarchyNode> children;
    private Set<String> parent;

    /**
     *
     */
    protected SubHierarchyNode() {
        children = new HashSet<SubHierarchyNode>();
        parent = new HashSet<String>();
    }

    /**
     *
     * @param id
     * @param name
     */
    protected SubHierarchyNode(String conceptId, String descriptorId, String category, String term) {
        children = new HashSet<SubHierarchyNode>();
        parent = new HashSet<String>();
        this.id = conceptId;
        this.name = term;
        data = new NodeData(conceptId, descriptorId, category, term);
    }

    protected SubHierarchyNode(SubHierarchyNode subHierarchyNode) {
        this.id = subHierarchyNode.getId();
        this.name = subHierarchyNode.getName();
        this.data = subHierarchyNode.getData();
        this.children = subHierarchyNode.getChildren();
        this.parent = subHierarchyNode.getParent();
    }
    
    

    public NodeData getData() {
        return data;
    }

    public void setData(NodeData data) {
        this.data = data;
    }

    /**
     *
     * @return
     */
    public String getId() {
        return id;
    }

    /**
     *
     * @param id
     */
    public void setId(String id) {
        this.id = id;
    }

    /**
     *
     * @return
     */
    public String getName() {
        return name;
    }

    /**
     *
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     *
     * @return
     */
    public Set<SubHierarchyNode> getChildren() {
        return children;
    }

    /**
     *
     * @param children
     */
    public void setChildren(Set<SubHierarchyNode> children) {
        this.children = children;
    }

    /**
     *
     * @param childNode
     */
    public void addChildren(SubHierarchyNode childNode) {
        children.add(childNode);
    }

    public boolean hasChildren(SubHierarchyNode childNode) {
        return children.contains(childNode);
    }

    public Set<String> getParent() {
        return parent;
    }

    public void setParent(Set<String> parent) {
        this.parent = parent;
    }

    public void addParent(String parentNodeId) {
        parent.add(parentNodeId);
    }

    public boolean hasParent(String parentNodeId) {
        return parent.contains(parentNodeId);
    }

    public boolean removeChild(SubHierarchyNode childNode) {
        return children.remove(childNode);
    }

    public boolean removeParent(String parentNodeId) {
        return parent.remove(parentNodeId);
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final SubHierarchyNode other = (SubHierarchyNode) obj;
        if ((this.id == null) ? (other.id != null) : !this.id.equals(other.id)) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 47 * hash + (this.id != null ? this.id.hashCode() : 0);
        return hash;
    }

    @Override
    public String toString() {
        return "Node{" + "id=" + id + ", name=" + name + ", data=" + data + ", childrens=" + children.size() + '}';
    }

    @Override
    protected Object clone() {
        return new SubHierarchyNode(this);
    }
}
